package com.zhouyu;

import china.MakerApplication;
import com.zhouyu.service.OrderService;
import com.zhouyu.service.TestBeanFactoryPostProcessor;
import com.zhouyu.service.User;
import com.zhouyu.service.UserService;
import com.zhouyu.test.TestAAA;
import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.SpringVersion;
import org.springframework.core.io.*;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.ServletContextResource;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;

import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;

// 我的微信：dadudu6789
// 我的公众号：IT周瑜
public class Test  {

public static class A{
	{
		System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAA");
	}
}
	public static void main(String[] args) throws Exception {


		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
//		ctx.scan("com.zhouyu");
		ctx.register(AppConfig.class);

//		AnnotatedBeanDefinitionReader annotatedBeanDefinitionReader = new AnnotatedBeanDefinitionReader(context);
//// 将User.class解析为BeanDefinition
//		annotatedBeanDefinitionReader.register(User.class);
//		System.out.println(context.getBean("user"));
//
//		 创建一个Spring容器
//		AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
//		ctx.scan("com.zhouyu");
//		ctx.addBeanFactoryPostProcessor(new TestBeanFactoryPostProcessor());
//		ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
//		ctx.register(AppConfig.class);
//		ctx.refresh();
//		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
		System.out.println(ctx.getBeanDefinitionCount() + "---");
		Tom tom = ctx.getBean( Tom.class);
		System.out.println("111111111111==>" + ctx.getBean(TestAAA.class).getClass());
		System.out.println("222222222222==>" + ctx.getBean(AspectJAwareAdvisorAutoProxyCreator.class));
		tom.helloWorld( );
		ctx.close();

		ClassRelativeResourceLoader classRelativeResourceLoader = new ClassRelativeResourceLoader(Test.class);
		System.out.println(classRelativeResourceLoader.getResource("AppConfig.class").exists());

//Spring中所有的Aware接口的的实现类
//		for (String s : "ApplicationContextAware, ApplicationEventPublisherAware, ApplicationStartupAware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, BootstrapContextAware, EmbeddedValueResolverAware, EnvironmentAware, ImportAware, LoadTimeWeaverAware, MessageSourceAware, NotificationPublisherAware, ResourceLoaderAware, SchedulerContextAware, ServletConfigAware, ServletContextAware".split(",")) {
//			System.out.println(s);
//
//		}
//		UrlResource urlResource = new UrlResource("https://repo.spring.io/ui/api/v1/download?repoKey=libs-snapshot-local&path=io%2Fspring%2Fge%2Fconventions%2Fgradle-enterprise-conventions-gradle-plugin%2F0.0.9-SNAPSHOT%2Fgradle-enterprise-conventions-gradle-plugin-0.0.9-20220111.211118-4.jar");
//		System.out.println(urlResource.getInputStream().read());

//		spring中所有的Initilizing实现类
//		String sss = "AbstractCacheManager, AbstractCacheResolver, AbstractColumnMaxValueIncrementer, AbstractDataFieldMaxValueIncrementer, AbstractEntityManagerFactoryBean, AbstractFactoryBean, AbstractHandlerMethodMapping, AbstractHandlerMethodMapping, AbstractIdentityColumnMaxValueIncrementer, AbstractJaxWsServiceExporter, AbstractJmsListeningContainer, AbstractMessageListenerContainer, AbstractMethodMessageHandler, AbstractMethodMessageHandler, AbstractPdfStamperView, AbstractPollingMessageListenerContainer, AbstractRefreshableConfigApplicationContext, AbstractRefreshableWebApplicationContext, AbstractRemoteSlsbInvokerInterceptor, AbstractRequestLoggingFilter, AbstractRoutingConnectionFactory, AbstractRoutingDataSource, AbstractSequenceMaxValueIncrementer, AbstractServiceLoaderBasedFactoryBean, AbstractSingletonProxyFactoryBean, AbstractSlsbInvokerInterceptor, AbstractTemplateView, AbstractTransactionSupportingCacheManager, AbstractUrlBasedView, AbstractUrlBasedView, AbstractXmlApplicationContext, AnnotationConfigWebApplicationContext, AnnotationMBeanExporter, BatchSqlUpdate, BeanConfigurerSupport, BeanValidationPostProcessor, CacheAspectSupport, CacheInterceptor, CacheProxyFactoryBean, CachingConnectionFactory, CachingDestinationResolverProxy, CciDaoSupport, CciLocalTransactionManager, CharacterEncodingFilter, ClassPathXmlApplicationContext, CommonsRequestLoggingFilter, CompositeCacheManager, ConcurrentMapCacheFactoryBean, ConfigurableMimeFileTypeMap, ConnectionFactoryInitializer, ConnectionSpecConnectionFactoryAdapter, ConnectorServerFactoryBean, ContentNegotiatingViewResolver, ContentNegotiationManagerFactoryBean, ContextLifecycleScheduledTaskRegistrar, ConversionServiceFactoryBean, CorsFilter, CronTriggerFactoryBean, CustomSQLExceptionTranslatorRegistrar, CustomValidatorBean, DaoSupport, DatabaseStartupValidator, DataSourceInitializer, DataSourceTransactionManager, DateTimeFormatterFactoryBean, DateTimeFormatterFactoryBean, Db2LuwMaxValueIncrementer, Db2MainframeMaxValueIncrementer, DB2MainframeSequenceMaxValueIncrementer, DB2SequenceMaxValueIncrementer, DefaultManagedAwareThreadFactory, DefaultManagedTaskExecutor, DefaultManagedTaskScheduler, DefaultMessageHandlerMethodFactory, DefaultMessageListenerContainer, DefaultPersistenceUnitManager, DelegatingConnectionFactory, DelegatingConnectionFactory, DelegatingDataSource, DelegatingFilterProxy, DerbyMaxValueIncrementer, EhCacheCacheManager, EhCacheFactoryBean, EhCacheManagerFactoryBean, EisOperation, EmbeddedDatabaseFactoryBean, EventPublicationInterceptor, ExceptionHandlerExceptionResolver, ExecutorConfigurationSupport, FieldRetrievingFactoryBean, FileSystemXmlApplicationContext, ForkJoinPoolFactoryBean, FormattingConversionServiceFactoryBean, FormContentFilter, ForwardedHeaderFilter, FreeMarkerConfigurationFactoryBean, FreeMarkerConfigurer, FreeMarkerConfigurer, FreeMarkerView, FreeMarkerView, FreeMarkerViewResolver, GenericFilterBean, GenericMessageEndpointManager, GenericSqlQuery, GenericStoredProcedure, GroovyMarkupConfigurer, GroovyMarkupView, GroovyWebApplicationContext, GsonFactoryBean, H2SequenceMaxValueIncrementer, HanaSequenceMaxValueIncrementer, HandlerMappingIntrospector, HessianClientInterceptor, HessianExporter, HessianProxyFactoryBean, HessianServiceExporter, HibernateDaoSupport, HibernateTemplate, HibernateTransactionManager, HiddenHttpMethodFilter, HsqlMaxValueIncrementer, HsqlSequenceMaxValueIncrementer, HttpComponentsAsyncClientHttpRequestFactory, HttpInvokerClientInterceptor, HttpInvokerProxyFactoryBean, HttpInvokerServiceExporter, HttpPutFormContentFilter, InterfaceBasedMBeanInfoAssembler, InternalResourceView, IsolationLevelDataSourceAdapter, IsolationLevelDataSourceRouter, Jackson2ObjectMapperFactoryBean, Jaxb2Marshaller, JaxWsPortClientInterceptor, JaxWsPortProxyFactoryBean, JCacheAspectSupport, JCacheCacheManager, JCacheInterceptor, JCacheManagerFactoryBean, JdbcAccessor, JdbcDaoSupport, JdbcTemplate, JdbcTransactionManager, JettyResourceFactory, JibxMarshaller, JmsAccessor, JmsDestinationAccessor, JmsGatewaySupport, JmsInvokerClientInterceptor, JmsInvokerProxyFactoryBean, JmsInvokerServiceExporter, JmsListenerEndpointRegistrar, JmsMessageEndpointManager, JmsMessagingTemplate, JmsTemplate, JmsTransactionManager, JndiObjectFactoryBean, JndiObjectLocator, JndiObjectTargetSource, JndiRmiClientInterceptor, JndiRmiProxyFactoryBean, JndiRmiServiceExporter, JobDetailFactoryBean, JpaTransactionManager, JstlView, JtaTransactionManager, JtaTransactionManagerFactoryBean, KeyNamingStrategy, LazyConnectionDataSourceProxy, ListFactoryBean, LocalConnectionFactoryBean, LocalContainerEntityManagerFactoryBean, LocalEntityManagerFactoryBean, LocalJaxWsServiceFactoryBean, LocalSessionFactoryBean, LocalSlsbInvokerInterceptor, LocalStatelessSessionProxyFactoryBean, LocalValidatorFactoryBean, MapFactoryBean, MappingCommAreaOperation, MappingRecordOperation, MappingSqlQuery, MappingSqlQueryWithParameters, MarshallingMessageConverter, MBeanClientInterceptor, MBeanExporter, MBeanProxyFactoryBean, MBeanServerConnectionFactoryBean, MBeanServerFactoryBean, MessageMappingMessageHandler, MessagingMessageConverter, MetadataMBeanInfoAssembler, MetadataNamingStrategy, MethodInvokingBean, MethodInvokingFactoryBean, MethodInvokingJobDetailFactoryBean, MethodInvokingRunnable, MethodMapTransactionAttributeSource, MethodValidationPostProcessor, MultipartFilter, MySQLMaxValueIncrementer, NamedCacheResolver, NamedParameterJdbcDaoSupport, NameMatchTransactionAttributeSource, Netty4ClientHttpRequestFactory, NotificationListenerBean, NotificationListenerRegistrar, ObjectFactoryCreatingFactoryBean, OncePerRequestFilter, OpenEntityManagerInViewFilter, OpenSessionInterceptor, OpenSessionInViewFilter, OptionalValidatorFactoryBean, OracleSequenceMaxValueIncrementer, PersistenceExceptionTranslationInterceptor, PostgreSQLSequenceMaxValueIncrementer, PostgresSequenceMaxValueIncrementer, PreferencesPlaceholderConfigurer, PropertiesFactoryBean, ProviderCreatingFactoryBean, ProxyFactoryBean, R2dbcTransactionManager, RdbmsOperation, ReactorResourceFactory, RedirectView, RedirectView, RelativeRedirectFilter, RemoteInvocationBasedAccessor, RemoteInvocationSerializingExporter, RequestContextFilter, RequestMappingHandlerAdapter, RequestMappingHandlerAdapter, RequestMappingHandlerMapping, RequestMappingHandlerMapping, RequestMappingInfoHandlerMapping, RequestMappingInfoHandlerMapping, ResourceAdapterFactoryBean, ResourceBundleViewResolver, ResourceHttpRequestHandler, ResourceUrlEncodingFilter, ResourceWebHandler, RmiClientInterceptor, RmiProxyFactoryBean, RmiRegistryFactoryBean, RmiServiceExporter, RouterFunctionMapping, RouterFunctionMapping, RSocketMessageHandler, ScheduledExecutorFactoryBean, ScheduledTaskRegistrar, SchedulerAccessorBean, SchedulerFactoryBean, ScriptTemplateView, ScriptTemplateView, ScriptTemplateViewResolver, ServerEndpointExporter, ServerResponseResultHandler, ServiceFactoryBean, ServiceListFactoryBean, ServiceLoaderFactoryBean, ServiceLocatorFactoryBean, ServletContextRequestLoggingFilter, ServletServerContainerFactoryBean, ServletWrappingController, SetFactoryBean, ShallowEtagHeaderFilter, SharedEntityManagerBean, SimpAnnotationMethodMessageHandler, SimpleCacheManager, SimpleCacheResolver, SimpleExceptionCacheResolver, SimpleHessianServiceExporter, SimpleHttpInvokerServiceExporter, SimpleHttpServerFactoryBean, SimpleHttpServerJaxWsServiceExporter, SimpleJaxWsServiceExporter, SimpleMessageListenerContainer, SimpleRecordOperation, SimpleRemoteSlsbInvokerInterceptor, SimpleRemoteStatelessSessionProxyFactoryBean, SimpleThreadPoolTaskExecutor, SimpleTriggerFactoryBean, SingleConnectionFactory, SingleConnectionFactory, SortedResourcesFactoryBean, SqlCall, SqlFunction, SqlOperation, SqlQuery, SqlServerMaxValueIncrementer, SqlUpdate, StoredProcedure, SybaseAnywhereMaxValueIncrementer, SybaseMaxValueIncrementer, TaskExecutorFactoryBean, ThreadPoolExecutorFactoryBean, ThreadPoolTaskExecutor, ThreadPoolTaskScheduler, TilesConfigurer, TilesView, TimerManagerAccessor, TimerManagerFactoryBean, TimerManagerTaskScheduler, TransactionAspectSupport, TransactionAwareCacheManagerProxy, TransactionAwareConnectionFactoryProxy, TransactionAwareDataSourceProxy, TransactionInterceptor, TransactionProxyFactoryBean, TransactionTemplate, UpdatableSqlQuery, UrlBasedRemoteAccessor, UrlBasedViewResolver, UserCredentialsConnectionFactoryAdapter, UserCredentialsDataSourceAdapter, ViewResolverComposite, WebLogicJtaTransactionManager, WebSocketAnnotationMethodMessageHandler, WebSphereDataSourceAdapter, WebSphereMBeanServerFactoryBean, WebSphereUowTransactionManager, WorkManagerTaskExecutor, WorkManagerTaskExecutor, XmlViewResolver, XmlWebApplicationContext, XsltView, XStreamMarshaller, YamlMapFactoryBean, YamlPropertiesFactoryBean\n";
//		for (String s : sss.split(",")) {
//			System.out.println(s);
//		}
//		FileCopyUtils.copy(new File("E:\\study\\spring-framework-5.3.10\\spring-core\\src\\main\\java\\org\\springframework\\util\\DigestUtils.java"),
//				new File("C:\\Users\\CAI\\Desktop\\222.java"));
//		System.out.println("==========" +SpringVersion.getVersion());

//		((ConfigurableApplicationContext) ctx).close();
		//		User user1 = ctx.getBean("user1", User.class);
// 		System.out.println(user1);


//		UserService userService1 = new UserService();
//
//		for (Field field : userService1.getClass().getDeclaredFields()) {
//			if (field.isAnnotationPresent(Autowired.class)) {
//				field.set(userService1, ??);
//			}
//		}
//
//
//		for (Method method : userService1.getClass().getDeclaredMethods()) {
//			if (method.isAnnotationPresent(PostConstruct.class)) {
//				method.invoke(userService1, null);
//			}
//		}
//
//		if (userService1 instanceof InitializingBean) {
//			try {
//				((InitializingBean)userService1).afterPropertiesSet();
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}
//
//		ProxyFactory proxyFactory = new ProxyFactory();
//		proxyFactory.setTarget(userService1);
//		proxyFactory.addAdvice(new MethodInterceptor() {
//			@Nullable
//			@Override
//			public Object invoke(@NotNull MethodInvocation invocation) throws Throwable {
//				System.out.println("切面逻辑 before...");
//				Object result = invocation.proceed();
////				Object result = invocation.getMethod().invoke(invocation.getThis(), invocation.getArguments());
//				System.out.println("切面逻辑 after...");
//				return result;
//			}
//		});
//		UserService userService2  = (UserService) proxyFactory.getProxy();
//		userService2.test();

	}
}







